package com.scorpionstudio.dantripro;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import com.scorpionstudio.utils.Constant;
import com.scorpionstudio.utils.MyDialog;

public class ShowInfoLink extends Activity {
	WebView wvInfo;
	private MyDialog myDialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_show_infomation);
		initUI();
		Bundle bdGetLink = getIntent().getExtras();
		if (bdGetLink != null) {
			String link = bdGetLink.getString(Constant.KEY_SEND_LINK);
			wvInfo.loadUrl(link);
		}
		myDialog = new MyDialog(ShowInfoLink.this, R.drawable.spinner);
		myDialog.setCancelable(true);
		myDialog.setCanceledOnTouchOutside(false);
		myDialog.setOnCancelListener(new OnCancelListener() {
			
			@Override
			public void onCancel(DialogInterface dialog) {
				dialog.dismiss();
				finish();
			}
		});
	}

	@SuppressLint("SetJavaScriptEnabled")
	private void initUI() {
		wvInfo = (WebView) findViewById(R.id.wv_info);
		wvInfo.setWebViewClient(new WebViewClient() {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			}
			
			public void onReceivedError(WebView view, int errorCode,
					String description, String failingUrl) {
				Toast.makeText(ShowInfoLink.this,
						"Web view cannot loading." + description,
						Toast.LENGTH_SHORT).show();
			}

			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				myDialog.show();
			}

			@Override
			public void onPageFinished(WebView view, String url) {
				myDialog.dismiss();
			}
		});
		wvInfo.getSettings().setBuiltInZoomControls(true);
		wvInfo.getSettings().enableSmoothTransition();
		wvInfo.getSettings().setJavaScriptEnabled(true);
	}

	@Override
	public void onBackPressed() {
		finish();
		super.onBackPressed();
	}
}
